import { post } from '@feidao-factory/send-msg/browser/request';
import global from '../../core/global';
import { ICommonParams, IHeaders } from '../../interfaces';
import get_sessionid from './_get-sessionid';

/*
 * 获取除去当前角色的其他角色
 * @param msg 系统参数，fd.data.msg
 * @param headers 系统参数，fd.data.hearders
 * @param productid 项目productid
 * @param clienttype 端点类型，web：3,h5：2,xcx:9
 */
export default async function get_roles(msg: ICommonParams, headers: IHeaders, productid: string, clienttype: string) {
	try {
		msg.url = window.location.href;
		// 获取cookie中的sessionid
		const sessionid = get_sessionid();
		msg.cookie.sessionid = sessionid;
		headers.sessionid = sessionid;

		const url = global.host + 'invoke-atom';
		const obj = {
			msg: [msg, headers, productid, clienttype],
			name: '@feidao-factory/atom/nodejs/authorization/get-roles'
		};
		const res = await post(url, JSON.stringify(obj));
		return JSON.parse(res.responseText);
	} catch (e) {
		console.error('--请求invoke-atom路由失败--错误信息---', e ? e.toString() : '');
		return Promise.reject(e);
	}
}
